package org.huawei260.TiKu;

/**
 * @Auther: qingle
 * @Date: 2024/10/31-15:38
 * @Description:
 * @version: 1.0
 */
import java.util.*;
public class B_2521_五子棋迷 {

//import java.util.Scanner;

//	public class FiveInARow {
		public static void main(String[] args) {
			Scanner scanner = new Scanner(System.in);
			int color = scanner.nextInt();
			scanner.nextLine(); // consume the newline
			String[] boardInput = scanner.nextLine().split(" ");
			int[] board = new int[boardInput.length];

			for (int i = 0; i < boardInput.length; i++) {
				board[i] = Integer.parseInt(boardInput[i]);
			}

			System.out.println(findBestMove(color, board));
		}

		public static int findBestMove(int color, int[] board) {
			int bestPosition = -1;
			int maxLength = 0;
			int middle = board.length / 2;

			for (int i = 0; i < board.length; i++) {
				if (board[i] == -1 || board[i] == 0) {
					int currentLength = calculateMaxLength(board, i, color);
					if (currentLength > maxLength ||
						(currentLength == maxLength && Math.abs(i - middle) < Math.abs(bestPosition - middle))) {
						maxLength = currentLength;
						bestPosition = i;
					}
				}
			}
			return bestPosition;
		}

		private static int calculateMaxLength(int[] board, int position, int color) {
			int leftCount = 0;
			int rightCount = 0;

			// Check left side
			for (int i = position - 1; i >= 0 && board[i] == color; i--) {
				leftCount++;
			}

			// Check right side
			for (int i = position + 1; i < board.length && board[i] == color; i++) {
				rightCount++;
			}

			// Include the current position
			int totalLength = leftCount + rightCount + 1;

			// Check if the length is valid
			return totalLength <= 5 ? totalLength : 0;
		}
	}
